package hn.cch.lettuce;

import hn.cch.lettuce.entity.ObjectEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class LettuceApplication {

    private static final Logger logger = LoggerFactory.getLogger(LettuceApplication.class);

    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(LettuceApplication.class, args);


        StringRedisTemplate stringRedisTemplate = applicationContext.getBean(
            "stringRedisTemplate", StringRedisTemplate.class);
        String key = "key";
        stringRedisTemplate.opsForValue().set(key, "value", 30L, TimeUnit.SECONDS);
        if (Objects.equals(stringRedisTemplate.hasKey(key), Boolean.TRUE)) {
            Long expire = stringRedisTemplate.getExpire(key);
            logger.info("redis[{}] expire:{}s", key, expire);
        }

    }




}
